package com.mt.system.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import com.mt.system.api.service.IRoleService;
import com.mt.system.entity.RoleEntity;
import com.mt.system.service.model.RoleServiceModel;

@Service
public class RoleServiceImpl implements IRoleService {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(RoleServiceImpl.class);

    @Autowired
    private RoleServiceModel roleServiceModel;

    public ServiceResult<RoleEntity> findInfo(Map<String, Object> params) {
        // 查询用户信息
        ServiceResult<RoleEntity> result = null;
        try {
            result = roleServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[RoleServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<List<RoleEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<RoleEntity>> result = new ServiceResult<List<RoleEntity>>();
        try {
            result = roleServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[RoleServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }

        return result;
    }

    public ServiceResult<Integer> doInsert(RoleEntity roleEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = roleServiceModel.insert(roleEntity);
        } catch (Exception e) {
            LOGGER.error("[RoleServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteById(Integer roleId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = roleServiceModel.deleteByPrimaryKey(roleId);
        } catch (Exception e) {
            LOGGER.error("[RoleServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(RoleEntity roleEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = roleServiceModel.updateByPrimaryKeySelective(roleEntity);
        } catch (Exception e) {
            LOGGER.error("[RoleServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "编辑信息错误");
        }
        return result;
    }

}
